//机票淡季旺季问题，将重复的语句结合到方法中，改进版
//夏梓豪
//2023/04/01


package Code1_2;

import java.util.Scanner;

public class test1_1 {
    public static void main(String[] args) {
        //输入信息，机票价格，机票类型，头等舱还是经济舱
        Scanner sc = new Scanner(System.in);
        System.out.println("请输入机票的原价：");
        int ticket = sc.nextInt();
        System.out.println("请输入机票的购买月份：");
        int month = sc.nextInt();
        if (month < 1 || month > 12){
            System.out.println("您输入了非法数据，程序结束！！！");
            System.exit(1);
        }
        System.out.println("请输入您购买的是经济舱还是头等舱：");
        String seat = sc.next();

        if(month >= 5 && month <=10){
            System.out.println("您需要给"+Getprice(seat,ticket,0.9,0.85)+"元");
        } else if (month >= 1 && month <=4 || month >= 11 && month <= 12) {
            System.out.println("您需要给"+Getprice(seat,ticket,0.7,0.65)+"元");
        }
    }

    public static double Getprice(String seat ,double price ,double discount1 ,double discount2 ) {
        switch (seat) {
            case "头等舱":
                double sum1 = price * discount1;
                return sum1;
            case "经济舱":
                double sum2 = price * discount2;
                return sum2;
        }
        return -1;
    }
    }

